<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>众筹单管理</title>
    <script src="../commonCss.js"></script>
    <script src="../commonJs.js"></script>
    <link rel="stylesheet" href="../../css/common.css">
</head>


<body class="skin-blue sidebar-mini">
<section class="content-header">
    <div class="ctc_title">众筹单管理</div>
    <div class="down_line"></div>
</section>

<!-- Main content -->
<section class="content" >
    <div class="row">
        <div class="col-xs-12" style="padding-left: inherit;">
            <div class="box-header">
                <form class="form-inline">
                    <label>查询:</label>
                    <div class="form-group">
                        <select class="form-control" id="searchSort">
                            <option value="2">降序</option>
                            <option value="1">升序</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <select class="form-control" id="searchStatus">
                            <option value="">选择状态</option>
                            <option value="0">待审核</option>
                            <option value="1">进行中</option>
                            <option value="2">付款中</option>
                            <option value="3">已结束</option>
                            <option value="4">进行中(已扣分) </option>
                            <option value="5">已驳回</option>
                            <option value="6">已失效</option>
                            <option value="21">付款中(暂停付款)</option>
                            <option value="22">进行中(已证明)</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <select class="form-control" id="searchCardType">
                            <option value="">选择收款银行卡类别</option>
                            <option value="1">储蓄卡</option>
                            <option value="2">支付宝</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <select class="form-control" id="flag">
                            <option value="">选择类型</option>
                            <option value="1">江湖救急</option>
                            <!--<option value="2">还房贷</option>-->
                            <!--<option value="3">还车贷</option>-->
                            <!--<option value="4">还信用卡</option>-->
                            <option value="5">求助</option>
                        </select>
                    </div>
                    <div class="form-group">
                        <input type="text" id="searchCrowd" class="form-control" style="width: 265px" placeholder="输入标题/发单人/用户账号/筹集金额搜索"/>
                    </div>

                    <div class="form-group">
                        <button type="button" onclick="getCrowdfund();"  class="btn btn-block btn-primary">搜索</button>
                    </div>
                </form>

            </div>
            <!-- 数据列表展示 -->
            <div class="box-body">
                <table id="crowdfundList" class="table table-bordered table-hover" >
                    <thead>
                    <tr>
                        <th>标题</th>
                        <th>类型</th>
                        <th>用户账号</th>
                        <th>发单人</th>
                        <th>众筹金额</th>
                        <th>已筹金额</th>
                        <th>账单金额</th>
                        <th>账单图片</th>
                        <th>结束时间</th>
                        <th>状态</th>
                        <th>操作</th>
                    </tr>
                    </thead>
                    <tbody>

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</section>

<!-- 【图片点击放大】弹出窗内容 -->
<div class="modal" id="picMonthDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" >
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span>
                </button>
                <h4 class="modal-title" align="center">账单</h4>
            </div>
            <img id="maxPic" width="100%">
        </div>
    </div>
</div>

<!-- 【信用扣分】弹出窗内容 -->
<div class="modal" id="punishDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" align="center" >信用扣分处罚</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <fieldset  style="margin-top: 1%;">
                        <div class="form-group">
                            <label class="col-md-2 control-label" style="color: red;">*扣除分数：</label>
                            <div class="col-md-10">
                                <select id="punishScore" class="form-control input-sm" style="width: 45%;">
                                    <option value="-5">5</option>
                                    <option value="-10">10</option>
                                    <option value="-15">15</option>
                                    <option value="-20">20</option>
                                    <option value="-25">25</option>
                                    <option value="-30">30</option>
                                    <option value="-35">35</option>
                                    <option value="-40">40</option>
                                    <option value="-45">45</option>
                                    <option value="-50">50</option>
                                </select>
                            </div>
                            <label class="col-md-2 control-label" style="color: red;">*扣分原因：</label>
                            <div class="col-md-10">
                                <textarea  id="reason" rows="12" cols="63"  style="margin-top: 2%;margin-bottom: 2%;" >
                                </textarea>

                                <label class="control-label" style="color: #0aa66e">常用原因：</label>
                                <select id="selReason" class="form-control" style="width: 85%;float: right;" onchange="selText()">
                                    <option value="">--请选择--</option>
                                    <option value="上传账单与实际消费不符合">上传账单与实际消费不符合</option>
                                    <option value="账单不真实">账单不真实</option>
                                    <option value="账单图片模糊">账单图片模糊</option>
                                    <option value="不是本人账单">不是本人账单</option>
                                </select>
                            </div>
                        </div>
                    </fieldset>
                </form>
            </div>
            <div class="modal-footer" style="text-align: center">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="confirmSubmit();">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- 【驳回】弹出窗内容 -->
<div class="modal" id="rejectDialog" tabindex="-1" role="dialog" aria-labelledby="mySmallModalLabel" aria-hidden="true" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal">
                    <span aria-hidden="true">×</span>
                    <span class="sr-only">Close</span>
                </button>
                <h4 class="modal-title" align="center" >众筹单驳回</h4>
            </div>
            <div class="modal-body">
                <form class="form-horizontal" onsubmit="return false">
                    <fieldset  style="margin-top: 1%;">
                        <div class="form-group">
                            <label class="col-md-2 control-label" style="color: red;">*驳回原因：</label>
                            <div class="col-md-10">
                                <textarea  id="rejectResion" rows="12" cols="63"  style="margin-top: 2%;margin-bottom: 2%;" >
                                </textarea>

                                <label class="control-label" style="color: #0aa66e">常用原因：</label>
                                <select id="selRejectReason" class="form-control" style="width: 85%;float: right;" onchange="selRejectText()">
                                    <option value="">--请选择--</option>
                                    <option value="上传账单与实际消费不符合">上传账单与实际消费不符合</option>
                                    <option value="账单不真实">账单不真实</option>
                                    <option value="账单图片模糊">账单图片模糊</option>
                                    <option value="不是本人账单">不是本人账单</option>
                                </select>
                            </div>
                        </div>
                    </fieldset>
                </form>
            </div>
            <div class="modal-footer" style="text-align: center">
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                <button type="button" class="btn btn-primary" onclick="confirmReject();">确定</button>
            </div>
        </div>
    </div>
</div>

<!-- page script -->
<script>
    $(document).ready(function() {
        //加载数据
        getCrowdfund();
    });

    function getCrowdfund(){
        var searchSort = $("#searchSort").val();
        if (searchSort == '2') {
            searchSort = 'desc';
        } else {
            searchSort = '';
        }
        var searchStatus = $("#searchStatus").val();
        var searchCardType = $("#searchCardType").val();
        var searchCrowd = $("#searchCrowd").val();
        var table = $('#crowdfundList').DataTable({
            "destroy": true,   //可以重新初始化，用于搜索
            "lengthChange": false,
            "ordering": false,   //排序
            "info": true,		   //
            "autoWidth": false,   //宽度自动
            "paging": true,      //分页
            "searching": false,  //全局搜索关闭
            "processing": true,  //开启显示‘正在加载.../processing’
            "serverSide":true,   //true代表后台处理分页，false代表前台处理分页
            "ajax" :  {
                url:"/crowdfund/getCrowdfundList",
                type:"post",
                data:{
                    "sort" : searchSort,
                    "status" : searchStatus,
                    "cardType" : searchCardType,
                    "keyWord" : searchCrowd,
                    "flag" : $("#flag").val()
                },
                dataSrc: function (myJson) {
                    return myJson.data.data;
                }
            },
            //参数显示
            "columns": [
                {"data": "title", 'sClass': "text-center",'width': '12%'},
                {"data": "type", 'sClass': "text-center",'width': '6%',
                    "render": function ( data, type, full, meta ) {
                        var str ;
                        if(data == 1){
                            str = "江湖救急"
                        }else if(data == 2){
                            str = "还房贷";
                        }else if(data == 3){
                            str = "还车贷";
                        }else if(data == 4){
                            str = "还信用卡";
                        }else if(data == 5){
                            str = "求助";
                        }
                        return str;
                    }
                },
                {"data": "userAccount", 'sClass': "text-center",'width': '6%'},
                {"data": "partyName", 'sClass': "text-center",'width': '6%'},
                {"data": "targetMoney", 'sClass': "text-center",'width': '6%'},
                {"data": "currentMoney", 'sClass': "text-center",'width': '6%'},
                {"data": "billMoney", 'sClass': "text-center",'width': '6%'},
                {"data": "img", 'sClass': "text-center",'width': '8%',
                    "render": function ( data, type, full, meta ) {
                        if(data == ''){
                            return "无";
                        }else{
                            var path = data.split("$")[0];
                            return "<img  style='width: 98px;height: 42px; '  src='"+path+"' onclick=maxPic('"+path+"')>";
                        }
                    }
                },
                {"data": "endTime", 'sClass': "text-center",'width': '7%',
                    "render": function ( data, type, full, meta ) {
                        return toDate(data).format('yyyy-MM-dd');
                    }
                },
                {"data": "status", 'sClass': "text-center",'width': '4%',
                    "render": function ( data, type, full, meta ) {
                        var str = "";
                        if(data==0){
                            str="<span class='label label-primary' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>待审核</span>";
                        }
                        if(data==1 ){
                            str="<span class='label label-success' style='padding-left:10px;padding-right:10px;padding-top: inherit;' >进行中</span> ";
                        }
                        if(data == 2) {
                            str="<span class='label label-warning' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>付款中</span>";
                        }
                        if(data == 3) {
                            str="<span class='label label-default' style='background-color:gray;padding-left:10px;padding-right:10px;padding-top: inherit;'>已完成</span>";
                        }
                        if(data == 4){
                            str="<span class='label label-success' style='padding-left:10px;padding-right:10px;padding-top: inherit;' >进行中(已扣分)</span> ";
                        }
                        if(data == 5){
                            str="<span class='label label-danger' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>已驳回</span>";
                        }
                        if(data == 6){
                            str="<span class='label label-default' style='background-color:gray;padding-left:10px;padding-right:10px;padding-top: inherit;'>已失效</span>";
                        }
//                        if(data == 21) {
//                            str="<span class='label label-warning' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>付款中</span><br><span class='label label-default' style='padding-left:10px;padding-right:10px;padding-top: inherit;'>(暂停付款)</span>";
//                        }
                        if(data==22){
                            str="<span class='label label-success' style='padding-left:10px;padding-right:10px;padding-top: inherit;' >进行中(已证明)</span> ";
                        }
                        return str;
                    }
                },
                {"data": "id" , 'sClass': "text-center" ,'width':'6%',
                    "render": function (data, type, full, meta ) {
                        var str ="";
                        if(full.status == 0 || full.status == 22){
                            str += "<a href = '#' title='审核通过' onclick=checkPass(" + data +");><i class='\glyphicon glyphicon-ok'></i></a>&nbsp;&nbsp;&nbsp;";
                        }
                        if(full.status == 1 || full.status == 22){
                            str += "<a href = '#' title='扣分' onclick=checkNotPass("+data+","+full.uid+");><i class='\glyphicon glyphicon-remove'></i></a>&nbsp;&nbsp;&nbsp;";
                        }
                        if(full.status == 0){
                            str += "<a href = '#' title='驳回' onclick=checkBack("+data+","+full.uid+");><i class='\glyphicon glyphicon-repeat'></i></a>&nbsp;&nbsp;&nbsp;";
                        }
//                        if(full.status == 2){
//                            str += "<a href = '#' title='暂停付款' onclick=pausePay("+data+","+full.uid+");><i class='\glyphicon glyphicon-stop'></i></a>&nbsp;&nbsp;&nbsp;";
//                        }
//                        if(full.status == 21){
//                            str += "<a href = '#' title='恢复付款' onclick=resumePay("+data+","+full.uid+");><i class='\glyphicon glyphicon-play'></i></a>&nbsp;&nbsp;&nbsp;";
//                        }
                        str += "<a href = '#' title='查看详情' onclick=viewDetail(" + data +");><i class='\glyphicon glyphicon-eye-open'></i></a>&nbsp;&nbsp;&nbsp;";
                        return str;
                    }
                }
            ],

            //是否开启主题
            "bJQueryUI": true,
            "oLanguage": {    // 语言设置
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "抱歉， 没有找到",
                "sInfo": "从 _START_ 到 _END_ /共 _TOTAL_ 条数据",
                "sInfoEmpty": "没有数据",
                "sInfoFiltered": "(从 _MAX_ 条数据中检索)",
                "sZeroRecords": "没有检索到数据",
                "sSearch": "检索:",
                "oPaginate": {
                    "sFirst": "首页",
                    "sPrevious": "前一页",
                    "sNext": "后一页",
                    "sLast": "尾页"
                }
            }
        });
    }

    //众筹信息审核通过
    function checkPass(id){
        if(confirm("确定审核通过该众筹单？")){
        	changeStatus(id,1);
        }
    }
    //付款中->暂停付款
    function pausePay(id){
        if(confirm("确定暂停付款？")){
            changeStatus(id,21);
        }
    }
    //暂停付款->付款中
    function resumePay(id){
        if(confirm("确定恢复付款？")){
            changeStatus(id,2);
        }
    }
    //提交审核通过
    function changeStatus(id,status) {
        $.ajax({
            url:"/crowdfund/editCrowdfundStatus",
            type:"POST",
            async : true,//默认就是true
            dataType:"json",
            data:{id : id,status : status},
            success:function(data) {
                layer.msg(data.message);
                getCrowdfund();
            }
        });
    }
    //上传的账单信息不通过，弹出扣分界面
    var cid ;
    var usid;
    function checkNotPass(crowdfundId,uid){
        $("#punishDialog").modal("show");
        cid = crowdfundId;
        usid = uid;
    }

    //确定处罚扣分
    function confirmSubmit() {
        var reso = $("#reason").val();
        if( $.trim(reso)  == ""){
            layer.msg("扣分原因不能为空");
            return ;
        }
        //1、通过审核
       // submitCheck(cid,4);
        //2、进行信用分扣除
        $.ajax({
            url:"/crowdfund/editCreditScoreByUserId",
            type:"POST",
            async : true,//默认就是true
            dataType:"json",
            data:{
                userId : usid,
                score : $("#punishScore").val(),
                reason : $("#reason").val(),
                cid :cid,
                status :4,
                id : cid,
                type : 5   //信用类型(1发红包 2互助 3登录 4其他 5违规)
            },
            success:function(data) {
                layer.msg(data.message);
                $("#punishDialog").modal("hide");
                getCrowdfund();
            }
        });
    }

    //驳回弹框
    var bcid ;
    function checkBack(crowdfundId,uid){
        $("#rejectDialog").modal("show");
        bcid = crowdfundId;
    }
    //确定驳回
    function confirmReject() {
        var reso = $("#rejectResion").val();
        if( $.trim(reso)  == ""){
            layer.msg("驳回原因不能为空");
            return ;
        }

        $.ajax({
            url:"/crowdfund/updCrowd",
            type:"POST",
            async : true,//默认就是true
            dataType:"json",
            data:{
                rejectResion : reso,
                cid :bcid,
                status :5
            },
            success:function(data) {
                layer.msg(data.message);
                $("#rejectDialog").modal("hide");
                getCrowdfund();
            }
        });
    }

    //查看众筹单筹款详情
    function viewDetail(id){
        window.location.href="crowdfundDetail.html?crdId="+id;
    }

    //选择常用扣分理由
    function selText() {
        var sel = $("#selReason").val();
        $("#reason").val(sel);
    }

    //选择常用驳回理由
    function selRejectText() {
        var sel = $("#selRejectReason").val();
        $("#rejectResion").val(sel);
    }

</script>
</body>
</html>
